package com.td.module.system.dal.mysql.video;

import com.td.framework.common.pojo.PageResult;
import com.td.framework.mybatis.core.mapper.BaseMapperX;
import com.td.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.td.module.system.controller.admin.video.vo.list.ListExportReqVO;
import com.td.module.system.controller.admin.video.vo.list.ListPageReqVO;
import com.td.module.system.dal.dataobject.video.ListDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 摄像头列 Mapper
 *
 * @author 王翔翔
 */
@Mapper
public interface ListMapper extends BaseMapperX<ListDO> {

    default PageResult<ListDO> selectPage(ListPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ListDO>()
                .eqIfPresent(ListDO::getDeviceSerial, reqVO.getDeviceSerial())
                .eqIfPresent(ListDO::getChannelNo, reqVO.getChannelNo())
                .likeIfPresent(ListDO::getChannelName, reqVO.getChannelName())
                .eqIfPresent(ListDO::getStatus, reqVO.getStatus())
                .eqIfPresent(ListDO::getIsEncrypt, reqVO.getIsEncrypt())
                .eqIfPresent(ListDO::getVideoLevel, reqVO.getVideoLevel())
                .orderByAsc(ListDO::getChannelNo));
    }

    default List<ListDO> selectList(ListExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<ListDO>()
                .eqIfPresent(ListDO::getDeviceSerial, reqVO.getDeviceSerial())
                .eqIfPresent(ListDO::getChannelNo, reqVO.getChannelNo())
                .likeIfPresent(ListDO::getChannelName, reqVO.getChannelName())
                .eqIfPresent(ListDO::getStatus, reqVO.getStatus())
                .eqIfPresent(ListDO::getIsEncrypt, reqVO.getIsEncrypt())
                .eqIfPresent(ListDO::getVideoLevel, reqVO.getVideoLevel())
                .orderByAsc(ListDO::getChannelNo));
    }

    default ListDO selectByChannelNo(Integer channelNo){
        return selectOne(ListDO::getChannelNo,channelNo);
    }

    @Select("SELECT id from video_list where id like #{id} Limit 1")
    ListDO selectByIds(String id);
}
